package dichotomyMethod;

import org.junit.Test;

/*
 *@description 寻找旋转排序数组中的最小值
 *@author hkfan
 *@version 1.0
 *@create 2025/5/16 09:20
 */
public class LeetCode_153 {

    @Test
    public void test(){
        System.out.println(findMin(new int[]{2,1}));
    }


    public int findMin(int[] nums) {

        //1. 定义初值
        int target = nums[0],l=0,r= nums.length-1;

        //2. 二分
        while(l<r){
            int mid = (l+r)/2;
            if (nums[mid]>=target){
                l=mid+1;
            }else {
                target = nums[mid];
                r=mid-1;
            }
        }
        return Math.min(target,nums[l]);


    }



}
